import re
from unidecode import unidecode


def decode_mixed_string(s):
    # 处理Unicode转义序列
    def decode_unicode_escapes(text):
        return re.sub(r"u([0-9a-fA-F]{4})", lambda m: chr(int(m.group(1), 16)), text)

    # 尝试解码混合编码
    try:
        # 先处理显式的Unicode转义
        s = decode_unicode_escapes(s)

        # 尝试UTF-8解码
        try:
            decoded = s.encode("latin1").decode("utf8", errors="ignore")
            if len(decoded) > len(s) / 2:  # 如果有显著解码结果
                s = decoded
        except:
            pass

        # 使用unidecode规范化字符
        normalized = unidecode(s)

        # 对比原始和解码结果，选择更有意义的一个
        return s if any(ord(c) > 127 for c in s) else normalized

    except Exception as e:
        print(f"解码出错: {e}")
        return s


# 测试解码
original_str = "uD83DuDC49Å©ÐÐµØÖ·ÊÕ1000Íò£¬ºÓ±±×Ê½ð£¬10-11£¬Íò1.7"
decoded_str = decode_mixed_string(original_str)

print("原始字符串:", original_str)
print("解码结果:", decoded_str)
